package com.hiwetop.cp;

import com.google.gson.Gson;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.os.WindowsUtils;

import java.io.*;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
import java.util.concurrent.TimeUnit;

/**
 * Created by linyu on 2016/12/9.
 */
public class Login {
    public static void main(String[] args) {
        WebDriver driver = DriverFactory.create();
        driver.get("http://0591night.com/forum.php?mod=forumdisplay&fid=38");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println(driver);
        WebElement user = driver
                .findElement(By.xpath("//input[@id='ls_username']"));
        user.clear();
        user.sendKeys("nimabibi");
        WebElement password = driver.findElement(By
                .xpath("//input[@id='ls_password']"));
        password.clear();
        password.sendKeys("nimabibi163");


        WebElement submit = driver.findElement(By
                .xpath("//button[contains(@class,'vm')]"));
        submit.submit();

        CookieUtil.getCookie(driver);

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        CookieUtil.setCookie(driver);
        driver.get("http://www.0591night.com/forum.php?mod=viewthread&tid=955&extra=page%3D1");
        WebElement tx = driver.findElement(By.id("fastpostmessage"));
        tx.sendKeys("小手一抖，金币到手来了");
        System.out.println(tx.getText());
        WebElement sub = driver.findElement(By.id("fastpostsubmit"));
        sub.submit();
        //driver.get("http://0591night.com/forum.php?mod=forumdisplay&fid=38");

        /*List<WebElement> elements = driver.findElements(By.cssSelector(".xst"));

        for (WebElement el :elements
             ) {
            el.click();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            WebElement tx = driver.findElement(By.id("fastpostmessage"));
            tx.sendKeys("小手一抖，金币到手来了");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            driver.get("http://0591night.com/forum.php?mod=forumdisplay&fid=38");
        }*/

    }
}
